Skip to content

Add wp menu item add-post-type-archive subcommand#594

Merged
swissspidy merged 4 commits intomainfrom
copilot/add-wp-menu-item-archive
Mar 15, 2026
Merged

Add wp menu item add-post-type-archive subcommand#594
swissspidy merged 4 commits intomainfrom
copilot/add-wp-menu-item-archive

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

wp menu item had no way to add post type archive pages as menu items, despite WordPress natively supporting the post_type_archive menu item type.

Changes

  • New subcommand add-post-type-archive in Menu_Item_Command — accepts <menu> and <post-type> positional args plus the standard optional flags (--title, --link, --description, --attr-title, --target, --classes, --position, --parent-id, --porcelain)
  • Validation — rejects unknown post types via get_post_type_object()
  • Delegates to the existing add_or_update_item() helper with type = post_type_archive
  • Behat tests — covers success path and invalid post type error
wp menu item add-post-type-archive sidebar-menu book
# Success: Menu item added.

wp menu item add-post-type-archive sidebar-menu book --title="All Books" --position=2
# Success: Menu item added.
Original prompt

This section details on the original issue you should resolve

<issue_title>Allow wp menu item command to add items of type post_type_archive</issue_title>
<issue_description>The wp menu item command allows for adding links to pages, links to posts and custom links, but doesn't allow for adding links to post type archive pages.

Please could this be added?

E.g. wp menu item add-archive

Thanks.</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera The current items match what the default admin backend provides: image 2018-10-23 at 5 27 51 pm

I don't think we need to limit ourselves to that, but if we go beyond "out-of-the-box" functionality, we should discuss what the scope we want to support should be. Just adding one random extension seems to arbitrary to my taste.

For now, I wonder whether we should just add a --relative flag to the menu item add-custom variant. This would allow for easy adding of the above archive pages, as well as many other types of links.

As an example, to add the CPT archive of a post that has a slug of books, we could use the following syntax:

wp menu item add-custom --relative my-menu "My Books" books

The --relative flag would let WP-CLI turn books into https://my-domain.com/books.</comment_new>
<comment_new>@swissspidy

I don't think we need to limit ourselves to that, but if we go beyond "out-of-the-box" functionality, we should discuss what the scope we want to support should be. Just adding one random extension seems to arbitrary to my taste.

FWIW Post type archive menu links are natively supported in WordPress (show_in_nav_menus option when registering a post type).</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@github-actions github-actions bot added command:menu Related to 'menu' command command:menu-item Related to 'menu item' command command:menu-item-add-custom Related to 'menu item add-custom' command labels Mar 15, 2026
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add wp menu item command to include post type archive Add wp menu item add-post-type-archive subcommand Mar 15, 2026
Copilot AI requested a review from swissspidy March 15, 2026 07:48
@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Menu_Item_Command.php 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy marked this pull request as ready for review March 15, 2026 08:32
@swissspidy swissspidy requested a review from a team as a code owner March 15, 2026 08:32
Copilot AI review requested due to automatic review settings March 15, 2026 08:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support in wp menu item for creating WordPress-native post_type_archive menu items, filling a functional gap in the menu item subcommands.

Changes:

  • Introduces wp menu item add-post-type-archive <menu> <post-type> in Menu_Item_Command.
  • Validates post type existence before delegating to the shared add_or_update_item() helper.
  • Adds a Behat scenario covering success and invalid post type error handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Menu_Item_Command.php Adds the add-post-type-archive subcommand and validation before calling add_or_update_item() with type=post_type_archive.
features/menu-item.feature Adds a Behat scenario exercising the new subcommand and an invalid post type error case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

swissspidy and others added 2 commits March 15, 2026 09:38
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@swissspidy swissspidy added this to the 2.9.0 milestone Mar 15, 2026
@swissspidy swissspidy merged commit b5ce8fe into main Mar 15, 2026
69 checks passed
@swissspidy swissspidy deleted the copilot/add-wp-menu-item-archive branch March 15, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:menu Related to 'menu' command command:menu-item Related to 'menu item' command command:menu-item-add-custom Related to 'menu item add-custom' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow wp menu item command to add items of type post_type_archive

4 participants